import { generateVideo, startPollingTaskStatus } from '@/api/VideoAI'

const handleGenerate = async () => {
  try {
    loading.value = true
    const response = await generateVideo({
      subject: form.subject,
      grade: form.grade,
      topic: form.topic,
      description: form.description,
      duration: form.duration
    })
    
    ElMessage.success('视频生成任务已提交，请等待处理...')
    
    startPollingTaskStatus(
      response.taskId,
      (videoUrl) => {
        ElMessage.success('视频生成完成')
        loading.value = false
        // 刷新视频列表
        fetchVideos()
      },
      (error) => {
        ElMessage.error(error)
        loading.value = false
      }
    )
  } catch (error) {
    ElMessage.error('视频生成失败：' + error.message)
    loading.value = false
  }
}

const form = ref({
  subject: '',
  grade: '',
  topic: '',
  description: '',
  duration: 30
})

const subjectOptions = [
  { value: 'chinese', label: '语文' },
  { value: 'math', label: '数学' },
  { value: 'english', label: '英语' },
  { value: 'physics', label: '物理' },
  { value: 'chemistry', label: '化学' },
  { value: 'biology', label: '生物' },
  { value: 'politics', label: '政治' },
  { value: 'history', label: '历史' },
  { value: 'geography', label: '地理' }
]

const gradeOptions = [
  { value: 'junior', label: '初中' },
  { value: 'senior', label: '高中' }
]

const durationOptions = [
  { value: 30, label: '30秒' },
  { value: 60, label: '1分钟' },
  { value: 120, label: '2分钟' },
  { value: 180, label: '3分钟' }
] 